import { app, BrowserWindow } from 'electron'
import { electronApp, optimizer } from '@electron-toolkit/utils'
import * as window from './gui/window.js'
import * as config from './biz/config/config.js'

//应用准备好了（main方法）
app.whenReady().then(() => {
  //禁用安全
  app.commandLine.appendSwitch('disable-web-security')
  // 设置windows应用的用户模型id
  electronApp.setAppUserModelId('com.qitian')

  // Default open or close DevTools by F12 in development
  // and ignore CommandOrControl + R in production.
  // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
  app.on('browser-window-created', (_, window) => {
    optimizer.watchWindowShortcuts(window)
  })
  //启动配置
  config.init()
  // 打开主窗口
  window.createWindow()
  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) window.createWindow()
  })
})

//绑定窗口都关闭，调用退出
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})
